/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Emanoel
 */
public class TrataBase {

    public static void main(String[] args) {
        BufferedReader br = null;
        BufferedWriter bw = null;
        try {
            br = new BufferedReader(new FileReader("src/rede/optdigits.tra"));
            bw = new BufferedWriter(new FileWriter("src/rede/optdigits_tratado.tra"));
            String linha = br.readLine();
            int j = 0;
            for (int i = 0; i < 10; i++) {
                j = 0;
                while ((linha != null) && (j < 15)) {
                    if (linha.charAt(linha.length() - 1) == ("" + i).charAt(0)){
                        bw.write(linha);
                        bw.write("\n");
                        j++;
                    }
                    linha = br.readLine();
                }
            }
        } catch (IOException ex) {
            Logger.getLogger(TrataBase.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                br.close();
                bw.close();
                System.out.println("Terminado.");
            } catch (IOException ex) {
                Logger.getLogger(TrataBase.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}
